#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>

using namespace std;
class Solution {
public:
    int minOperations(vector<int>& nums, int x) {
        int sum = 0;
        for (auto e : nums)
        {
            sum += e;
        }


        int target = sum - x;
        if (target < 0)
            return -1;

        int left = 0, right = 0;
        int n = nums.size();
        int len = -1;
        sum = 0;
        while (right < n)
        {
            sum += nums[right];

            while (sum > target)
            {
                sum -= nums[left++];
            }

            if (sum == target)
            {
                len = max(len, right - left + 1);
            }

            right++;
        }

        return len == -1 ? -1 : n - len;
    }
};

int main()
{
	return 0;
}